<?php
namespace Admin\Controller;
class DcomController extends IsloginController{
	function oper(){
		$dcom = M("Gongsi");
        if(isset($_SERVER["HTTP_X_REQUESTED_WITH"]) && strtolower($_SERVER["HTTP_X_REQUESTED_WITH"])=="xmlhttprequest"){

        }else{
            // 正常请求的处理方式
            $num=$dcom->count();
// 		3、规定每页显示的条数
            $pageSize=12;
// 		4、实例化分页类
            $pageOb=new \Think\Page($num,$pageSize);
// 		5、获取开始位置值
            $start=$pageOb->firstRow;
// 		6、获取分页结果
            $pageStr=$pageOb->show();
            $arr = $dcom->limit("$start,$pageSize")->order('id desc')->select();
            $this->assign('pageStr',$pageStr);
        };
		if($arr){
			$this->assign('arr',$arr);
		}else{
		}
		$this->show();
	}	
	function update(){
		$up = M("Gongsi");
		$id=$_GET["id"];
		$arr = $up->where("id=$id")->find();
		$this->assign('arr',$arr);
		$this->display();
	}
	function save(){
		$upload= new \Think\Upload();
		$upload->autoSub  =false;
		$upload->mimes=array('image/png',"image/gif","image/jpeg");
		$upload->rootPath = './Public';
       	$upload->savePath = '/Upload/';
		$info=$upload->upload();
		if($info){
			$_POST['imagename']=$info['imagename']['savename'];
		}
		$up = M("Gongsi");
		$_POST['addtime']=time();
		$re = $up->data($_POST)->save();
		if($re){
			$this->success("修改成功",U("Dcom/oper"));
		}else{
		}
	}
	function del(){
		$up = M("Gongsi");
		$id=$_POST["id"];
		$re = $up->where("id=$id")->delete();
		if($re){
			$this->success("删除成功！",U("Dcom/oper"));
		}else{
			$this->error("删除失败！",U("Dcom/oper"));
		}
	}
	function add(){
		/* if (IS_POST) {  
        } else {
          $region = M('Province')->select();
          $this->assign('region',$region);
          $this->display();
        }
			$code = $_POST['pro_code'];
			$region = M('City')->where("provincecode=$code")->select();		
			foreach($region as $key=>$val){
		    $opt .= "<option value='{$val['code']}'>{$val['name']}</option>";
		 }
		echo json_encode($opt); 
    }
    public function area(){
          $code = $_POST["city_code"];
          $region = M('Area')->where("citycode=$code")->select();
		  foreach($region as $key=>$val){
		  $opt .= "<option value='{$val['code']}'>{$val['name']}</option>";
		 }
		echo json_encode($opt); */
		$this->display();
    }

	function tianjia(){
		$upload= new \Think\Upload();
		$upload->autoSub  =false;
		$upload->mimes=array('image/png',"image/gif","image/jpeg");
		$upload->rootPath = './Public';
       	$upload->savePath = '/Upload/';
		$info=$upload->upload();
		if($info){
			$_POST['imagename']=$info['imagename']['savename'];
		}
		$dcom=M("Gongsi");
		$_POST['ip']=get_client_ip();
		$_POST['addtime']=time();
        $haoping = rand(9000,15000);
        $zixunnum = rand(15000,20000);
		$_POST['koubei']=$haoping;
		$_POST['zixunnum']=$zixunnum;
		var_dump($_POST);
		$re = $dcom->data($_POST)->add();
        if($re){
            $this->success("添加成功！",U("Dcom/oper"));
        }else{
            $this->error("添加失败！",U("Dcom/oper"));
        }
	}
	function zczz(){
        $ob = M("Comzhuce");
        $zcid=$_GET["zcid"];
        $arr = $ob->where("zcid=$zcid")->find();
        $a = array("zcid"=>$zcid);
        array_unshift($arr,$a);
        var_dump($arr);
        $this->assign('arr',$arr);
		$this->display();
	}
	function zczzadd(){
	$zcOb = M("Comzhuce");
	if(!empty($_POST['zcid'])){
        $re = $zcOb->data($_POST)->add();
        if($re){
            $this->success("添加成功！",U("Dcom/oper"));
        }else{
            $this->error("添加失败！",U("Dcom/oper"));
        }
    }else{
        $re = $zcOb->data($_POST)->save();
        if($re){
            $this->success("添加成功！",U("Dcom/oper"));
        }else{
            $this->error("添加失败！",U("Dcom/oper"));
            }
        }
    }
    function seachs(){
        if(isset($_SERVER["HTTP_X_REQUESTED_WITH"]) && strtolower($_SERVER["HTTP_X_REQUESTED_WITH"])=="xmlhttprequest") {
            $biao = M("Gongsi");
            $_county = $_POST["s_county"];
            $county = $biao->where("s_county='$_county'")->select();
            $this->ajaxReturn($county);
        }
    }
    function sachi(){
        if(isset($_SERVER["HTTP_X_REQUESTED_WITH"]) && strtolower($_SERVER["HTTP_X_REQUESTED_WITH"])=="xmlhttprequest") {
            $biao = M("Gongsi");
            $keyword = $_POST["keyword"];
            $data['cname|id|s_city|s_province|s_county'] = array('like', "%$keyword%");
            $keyarr = $biao->where($data)->select();
            $this->ajaxReturn($keyarr);
        }
    }

}
